package patrol.mobile.com.mobilepatrol.activity.office;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.activity.MissionRegisterActivity;
import patrol.mobile.com.mobilepatrol.adapter.MyHomeNewAdapter;
import patrol.mobile.com.mobilepatrol.bean.HomeDataBean;
import patrol.mobile.com.mobilepatrol.bean.MenuConstants;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;

public class OfficeHomeActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private MyHomeNewAdapter mAdapter;
//    private int[] img1 = new int[]{R.mipmap.unit_profile, R.mipmap.party_information, R.mipmap.highway_maintenance, R.mipmap.charge_service, R.mipmap.safety_production, R.mipmap.visit_gather, R.mipmap.assess_pool, R.mipmap.other_queries};
    //    private int[] imgTitle = new int[]{R.mipmap.iv_total_search, R.mipmap.iv_day_manage, R.mipmap.iv_other_bus};
//    private int[] imgTitle = new int[]{R.mipmap.iv_total_search, R.mipmap.iv_other_bus};
    //    private int[] img2 = new int[]{R.mipmap.l6};
//    private int[] img2 = new int[]{R.mipmap.suggestions};
//    private int[] img3 = new int[]{R.mipmap.other, R.mipmap.other};

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_office_home;
    }

    @Override
    public void initTitle() {
        super.initTitle();
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CommonUtil.exitActivityAndBackAnim(OfficeHomeActivity.this, true);
                    }
                });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("行政管理");
    }

    @Override
    public void initData() {
        super.initData();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new MyHomeNewAdapter(this);
//        mAdapter.setTitleData(imgTitle);
        recyclerView.setAdapter(mAdapter);

//        String[] stringTopTitleArray = getResources().getStringArray(R.array.office_top_title);
//        String[] stringTopTitleSub1Array = getResources().getStringArray(R.array.office_top_title_sub1);
////        String[] stringTopTitleSub2Array = getResources().getStringArray(R.array.office_top_title_sub2);
//        String[] stringTopTitleSub3Array = getResources().getStringArray(R.array.office_top_title_sub3);
        List<HomeDataBean> list1 = new ArrayList<>();
        int[] ints = new int[]{R.mipmap.home_lease};
        for (int i = 0; i < MenuConstants.XZGL_TOP_TITLES.length; i++) {
            HomeDataBean homeDataBean = new HomeDataBean();
            homeDataBean.setTopTitle(MenuConstants.XZGL_TOP_TITLES[i]);
            List<HomeDataBean.DataBean> list2 = new ArrayList<>();
            if (i == 0) {
                for (int i1 = 0; i1 < MenuConstants.XZGL_CHILD_TITLES_1.length; i1++) {
                    HomeDataBean.DataBean dataBean = new HomeDataBean.DataBean(MenuConstants.XZGL_CHILD_TITLES_1[i1], MenuConstants.XZGL_CHILD_IMGS_1[i1]);
                    list2.add(dataBean);
                }
            }
//            else if (i == 1) {
//                for (int i1 = 0; i1 < stringTopTitleSub2Array.length; i1++) {
//                    HomeDataBean.DataBean dataBean = new HomeDataBean.DataBean(stringTopTitleSub2Array[i1], img2[i1]);
//                    list2.add(dataBean);
//                }
//            }
//            else {
//                for (int i1 = 0; i1 < stringTopTitleSub3Array.length; i1++) {
//                    HomeDataBean.DataBean dataBean = new HomeDataBean.DataBean(stringTopTitleSub3Array[i1], img3[i1]);
//                    list2.add(dataBean);
//                }
//            }
            homeDataBean.setData(list2);
            list1.add(homeDataBean);
        }
        mAdapter.setData(list1);
    }

    @Override
    public void setListener() {
        mAdapter.setItemClickListener(new MyHomeNewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int parentPosition, int childPosition) {
                if (parentPosition == 0) {
                    if (childPosition == 0 || childPosition == 1 || childPosition == 2 || childPosition == 3 || childPosition == 4 || childPosition == 5) {
                        Intent intent = new Intent(OfficeHomeActivity.this, NewsListActivity.class);
                        intent.putExtra(NewsListActivity.TITLE, childPosition);
                        startActivity(intent);//新闻列表
                    } else if (childPosition == 6) {
//                        startActivity(ExaminationAllActivity.class);//考核汇总
                        startActivity(JiXiaoHuiZongActivity.class);//考核汇总
                    } else {
                        startActivity(OtherBusinessSearchActivity.class);//其它业务查询
                    }
                }
//                else if (parentPosition == 1) {
//                    startActivity(AdviceActivity.class);//意见建议
//                }
                else if (parentPosition == 1) {
                    if (childPosition == 0) {
                        startActivity(OtherBusinessActivity.class);//其它业务
                    } else if (childPosition == 1) {
                        startActivity(MissionRegisterActivity.class);
                    }

                }
            }
        });
    }
}
